//app.js

App({
  onLaunch: function() {
    //调用API从本地缓存中获取数据
    //var logs = wx.getStorageSync('logs') || []
    // logs.unshift(Date.now())
    //wx.setStorageSync('logs', logs)
  },
  getUserInfo: function(cb) {
    var that = this
    if (this.globalData.userInfo) {
      console.info("全局userino")
      typeof cb == "function" && cb(this.globalData.userInfo)
    } else {
      //调用登录接口
      console.info("调用登录接口userino")
      wx.login({
        success: function(res) {
          var code = res.code;
          wx.getUserInfo({
            success: function(res) {
              wx.request({
                url: that.globalData.domain + 'api/get_user_info',
                method: 'post',
                data: {
                  userInfo: res,
                  code: code,
                  APPID: that.globalData.APPID,
                  SECRET: that.globalData.SECRET
                },
                success: function (res) {
                  that.globalData.userInfo = res.data.userInfo
                  typeof cb == "function" && cb(that.globalData.userInfo)
                },
                fail: function () {
                  that.globalData.userInfo = null
                  typeof cb == "function" && cb(that.globalData.userInfo)
                }
              });
            },fail:function(res){
              wx.openSetting({
                success:(res)=>{
                  if(res.authSetting["scope.userInfo"]){}
                  else{}
                },
                fail:function(){
                  fail()
                }

              })
            }
          });
        }
      })
    }

    // wx.checkSession({
    //   success: function(res) {
    //     console.log('成功', res);
    //   },
    //   fail: function(res) {
    //     console.log('失败', res);
    //   }
    // });



  },


  globalData: {
    getTime: function() {
      return new Date().getTime();
    },
    // domain: 'https://app.liangyan.vip/appweb/',
    //domain: 'http://10.204.127.36:8001/appweb/',
    domain: 'http://127.0.0.1:8001/appweb/',
    // domain: 'https://app.lba.org.cn/appweb/',
    APPID: 'wx91565ea9a81ea7fc',
    SECRET: '6af8514e6c09757f046e6889496ddf6d',
    // APPID: 'wx35d2898163d6cc92',
    // SECRET: 'cd2b6c7656a6b2d6930310c37017abbc',
    userInfo: null
  }
})
